package com.hq.ims.data.entityenum;

import com.hq.utils.exception.CommonException;
import com.hq.web.penum.IBaseEnum;

/**
 * @detail 审核状诚
 */
public enum EnumAuditStatus implements IBaseEnum {

    PendingReview(0, "待提交"),

    UnderReview(1, "审核中"),

    Pass(2, "通过"),

    NotPass(3, "驳回"),

    CancelAudit(4, "已撤回"),
    ;

    private final int code;

    private final String typeName;

    EnumAuditStatus(int code, String typeName) {
        this.code = code;
        this.typeName = typeName;
    }

    public static boolean isCanEdit(EnumAuditStatus status) {
        if (status == EnumAuditStatus.UnderReview || status == EnumAuditStatus.Pass) {
            return false;
        }
        return true;
    }

    public static boolean isCanDel(EnumAuditStatus status) {
        if (status == EnumAuditStatus.PendingReview || status == EnumAuditStatus.NotPass || status == EnumAuditStatus.CancelAudit) {
            return true;
        }
        return false;
    }

    public static void isCanEditTh(EnumAuditStatus status) {
        if (status == EnumAuditStatus.UnderReview) {
            throw CommonException.build("数据正在审核中,暂不能处理");
        } else if (status == EnumAuditStatus.Pass) {
            throw CommonException.build("数据已通过审核,不允许变更");
        }
    }

    public static void isCanDelTh(EnumAuditStatus status) {
        if (status == EnumAuditStatus.Pass) {
            throw CommonException.build("数据已通过审核,不允许变更");
        }
    }

    public static void isCanCancelTh(EnumAuditStatus status) {
        if (status != EnumAuditStatus.UnderReview) {
            throw CommonException.build("数据不是审核中,不允许撤销");
        }
    }

    public static void isCanAuditTh(EnumAuditStatus status) {
        if (status == EnumAuditStatus.Pass || status == EnumAuditStatus.NotPass) {
            throw CommonException.build("数据已审核完成!");
        }else if(status == EnumAuditStatus.CancelAudit){
            throw CommonException.build("数据已撤销!");
        }
    }

    @Override
    public int getCode() {
        return code;
    }

    @Override
    public String getValue() {
        return typeName;
    }

    public String getTypeName() {
        return typeName;
    }
}
